<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="wrap">
        <button class="btn1">删除节点</button>
        <ul class="list">
            <li class="first">1</li>
            <li>2</li>
            <li class="mid">3</li>
            <li>4</li>
            <li>5</li>
            <li class="last">6</li>
        </ul>
    </div>
</body>
<script>
    // 节点
    // 文档节点  元素节点 属性节点 文本节点 注释节点

    var ul = document.getElementsByClassName("list")[0];
    var mid = document.getElementsByClassName("mid")[0];
    var btn1 = document.getElementsByClassName("btn1")[0];


    // 如何删除节点? 
    // (1) Element.remove();    自删
    // (2) ParentNode.removeChild(Node)  父删

    // 点击按钮  删除mid
    btn1.onclick = function () {

        // if(mid){
        //     mid.remove();
        //     mid = null;
        // }

        if (mid) {
            ul.removeChild(mid);
            mid = null;
        }

    }




    function randColor() {
        var str = "0123456789abcdef";

        var colorStr = "#";
        for (var i = 0; i < 6; i++) {
            var index = Math.floor(Math.random() * str.length);
            var char = str.charAt(index);
            colorStr += char;
        }
        return colorStr;
    }



</script>

</html>